package top.lingchen.webfluxdemo1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import top.lingchen.webfluxdemo1.entity.User;
import top.lingchen.webfluxdemo1.service.UserService;

/**
 * @Author 凌宸
 * @create 2021-12-01 下午 6:07
 * @Description
 * @Version 1.0
 */
@RestController
public class UserController {
    // 注入 service
    @Autowired
    private UserService userService;

    // id 查询
    @GetMapping("/user/{id}")
    public Mono<User> getUserById(@PathVariable int id){
        return userService.getUserById(id);
    }
    // 查询所有
    @GetMapping("/user")
    public Flux<User> getUsers(){
        return userService.getAllUsers();
    }
    // 添加
    @PostMapping("/saveuser")
    public Mono<Void> saveUser(@RequestBody User user){
        Mono<User> userMono = Mono.just(user);
        return userService.saveUserInfo(userMono);
    }

}
